function ch_select(flag, clazz) {
	var ch = flag || false;
	var inputs = document.getElementsByTagName("input");
	for ( var i = 0; i < inputs.length; i++) {
		if (inputs[i].type == "checkbox") {
			if (clazz != undefined) {
				if (inputs[i].className == clazz) {
					inputs[i].checked = ch;
				}
			} else {
				inputs[i].checked = ch;
			}
		}
	}
	return false;
}

function getBrowser() {
	var sBrowser = navigator.userAgent;
	if (sBrowser.toLowerCase().indexOf('msie') > -1)
		return 'ie';
	else if (sBrowser.toLowerCase().indexOf('firefox') > -1)
		return 'firefox';
	else
		return 'mozilla';
}
/**
 * 
 * @param m month
 * @param d date
 * @param y year
 * @return true if valid date, false otherwise
 */
function checkdate(m, d, y) {
	return m > 0 && m < 13 && y > 0 && y < 32768 && d > 0
			&& d <= (new Date(y, m, 0)).getDate();

}
function isNumeric(Nstring) {
	return !isNaN(Nstring);
}

function checkNumericField(field) {
	if (!isNumeric(field.value)) {
		field.value = "";
		return false;
	}
	return true;
}

function checkNumericField(field, maxVal) {
	if (!isNumeric(field.value)) {
		field.value = "";
		return false;
	} else {
		if (field.value < 1 || field.value > maxVal) {
			field.value = "";
			return false;
		}
	}
	return true;
}
function moveToNextField(form, field, nxtField, maxLength) {

	if (field.value.length == maxLength) {
		form.elements[nxtField].focus();
	}

}
/**
 * The function below checks if a required field has been left empty.
 * If the required field is blank, an alert box alerts a message and the function returns false. 
 * If a value is entered, the function returns true (means that data is OK):
 * @param field
 * @param alerttxt
 * @return
 */
function validate_required(field, alerttxt) {
	with (field) {
		if (value == null || value == "") {
			alert(alerttxt);
			return false;
		} else {
			return true;
		}
	}
}

function validate_length(field, field_name, max_length) {
	with (field) {
		if (value.length > max_length) {
			alert("Maxinum length for " + field_name + " is " + max_length + " characters!");
			return false;
		} else {
			return true;
		}
	}
}

function compareTwoDate(date1, date2) {
	return date1 - date2;

}

/* assumed to be in MM/DD/YYYY format */

function getAgeFromBirthDate(DOB) {
	var today = new Date();
	var d = DOB.split("/");
	var byr = parseInt(d[2]);
	var bmmdd = 100 * parseInt(d[0], 10) + parseInt(d[1], 10); // get MMDD as integer

	var age = today.getFullYear() - byr;
	if (bmmdd > (today.getMonth() * 100 + 100 + today.getDate()))
		--age;
	return age;
}

//Functions added by Umme Essa


function getLength(nodes){
 	if(nodes.length) return nodes.length;
 	return 1;
 }
 function getItemAt(nodes,i){
 	if(nodes.length) return nodes[i];
 	return nodes;
 }
 